package com.zmn.plat.services.impl.orderconfig.documentarycontent;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.orderconfig.documentarycontent.DocumentaryContent;
import com.zmn.plat.model.entity.orderconfig.documentarycontent.DocumentaryContentQuery;
import com.zmn.plat.persistence.interfaces.orderconfig.documentarycontent.DocumentaryContentDAO;
import com.zmn.plat.services.interfaces.orderconfig.documentarycontent.DocumentaryContentService;

/**
 * 类描述:跟单内容service实现类
 *
 * @author linfeng
 * @since 2019/10/22/12:01
 */
@Service
public class DocumentaryContentServiceImpl implements DocumentaryContentService {
    @Resource
    DocumentaryContentDAO documentaryContentDao;

    @Override
    public Integer countByQuery(DocumentaryContentQuery query) {
        return documentaryContentDao.countByQuery(query);
    }

    @Override
    public DocumentaryContent findByKey(Integer id) {
        return documentaryContentDao.findByKey(id);
    }

    @Override
    public List<DocumentaryContent> listPageByQuery(DocumentaryContentQuery query) {
        int count = documentaryContentDao.countByQuery(query);
        query.setTotalCount(count);
        return documentaryContentDao.listPageByQuery(query);
    }

    @Override
    public List<DocumentaryContent> listByQuery(DocumentaryContentQuery query) {
        return documentaryContentDao.listByQuery(query);
    }

    @Override
    public int updateStatusBatch(List<Integer> arrayIds, int status, String updater) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(updater);
        dto.setUpdateTime(DateUtil.getNow());
        return documentaryContentDao.updateStatusBatch(dto);
    }

    @Override
    public Integer updateSortKey(int id, int sort, String updater) {
        DocumentaryContent documentaryContent = new DocumentaryContent();
        documentaryContent.setId(id);
        documentaryContent.setSort(sort);
        documentaryContent.setUpdater(updater);
        documentaryContent.setUpdateTime(DateUtil.getNow());
        return documentaryContentDao.updateSortKey(documentaryContent);
    }

    @Override
    public Integer updateFirstLetterByKey(int id, String firstLetter, String updater) {
        DocumentaryContent documentaryContent = new DocumentaryContent();
        documentaryContent.setId(id);
        documentaryContent.setFirstLetter(firstLetter);
        documentaryContent.setUpdater(updater);
        documentaryContent.setUpdateTime(DateUtil.getNow());
        return documentaryContentDao.updateFirstLetterByKey(documentaryContent);
    }

    @Override
    public Integer updateByKey(DocumentaryContent documentaryContent) {
        return documentaryContentDao.updateByKey(documentaryContent);
    }

    @Override
    public Integer insert(DocumentaryContent documentaryContent) {
        return documentaryContentDao.insert(documentaryContent);
    }
}
